#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include "matrix.h"

void choose(double *matrix, double shu, int rows, int cols)
{
    char sign;
    double constant;
    char tip[]="大大，您所需的常数是: ";
    if( shu == 1)
	{
    	sign='+';
    	puts(tip);
    	scanf("%lf", &constant);
    	printf("您的结果矩阵是:\n");
    	change(matrix, rows, cols, constant, sign);
	}
	else if( shu == 2)
	{
		sign='-';
		puts(tip);
    	scanf("%lf", &constant);
    	printf("您的结果矩阵是:\n");
		change(matrix, rows, cols, constant, sign);
	}
	else if( shu == 3)
	{
    	sign='*';
    	puts(tip);
    	scanf("%lf", &constant);
    	printf("您的结果矩阵是:\n");
    	change(matrix, rows, cols, constant, sign);
	}
	else if( shu== 4)
	{
		printf("您的转置矩阵是:\n");
		double *temp = (double *)malloc(cols * rows * sizeof(double));  // 动态分配内存
        if (temp == NULL) 
		{
        printf("内存分配失败！\n");
        exit(1);
        }
		temp = transpose(matrix, rows, cols);
		for (int i = 0; i < cols; i++) 
		{
           for (int j = 0; j < rows; j++) 
		   {
             printf("%lf ", temp[i * rows + j]);
           }
        printf("\n");
        }
    }
    else if(shu == 5)
	{
    	if(rows != cols)
		{
    		printf("大大，您输入的矩阵没有逆矩阵！！！\n");
		}
		else
		{
			int n=rows;
			inverse(matrix, n, shu);
			printf("\n");
		}
	}
	else if(shu == 6)
	{   
	    printf("[5] 大大，你的矩阵秩是: ");
		int n=rows;
		double result_2 = determinant(matrix, n, shu);
		printf(" %.0lf \n", result_2);
	}
	else 
	{
      	printf("<5> 大大，您输入错误了，请根据上面提示来输入噢\n");
	}
}